package com.ruoyi.alarm.service.impl;

import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import com.ruoyi.base.service.IBaseDeviceService;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.manufacturer.ControlCommand;
import com.ruoyi.manufacturer.ControlVo;
import com.ruoyi.manufacturer.IPlatform;
import com.ruoyi.manufacturer.PlatformTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.alarm.mapper.AlarmRuleMapper;
import com.ruoyi.alarm.domain.AlarmRule;
import com.ruoyi.alarm.service.IAlarmRuleService;

/**
 * 告警规则Service业务层处理
 * 
 * @author yepanpan
 * @date 2025-03-10
 */
@Service
public class AlarmRuleServiceImpl implements IAlarmRuleService 
{
    public static final String CACHE_MAP = "alarm_rule";
    private static final Logger log = LoggerFactory.getLogger(AlarmRuleServiceImpl.class);
    private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);

    @Autowired
    private AlarmRuleMapper alarmRuleMapper;
    @Autowired
    private IBaseDeviceService baseDeviceService;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询告警规则
     * 
     * @param id 告警规则主键
     * @return 告警规则
     */
    @Override
    public AlarmRule selectAlarmRuleById(Long id)
    {
        return alarmRuleMapper.selectAlarmRuleById(id);
    }

    /**
     * 查询告警规则列表
     * 
     * @param alarmRule 告警规则
     * @return 告警规则
     */
    @Override
    public List<AlarmRule> selectAlarmRuleList(AlarmRule alarmRule)
    {
        return alarmRuleMapper.selectAlarmRuleList(alarmRule);
    }

    /**
     * 新增告警规则
     * 
     * @param alarmRule 告警规则
     * @return 结果
     */
    @Override
    public int insertAlarmRule(AlarmRule alarmRule)
    {
        alarmRule.setCreateTime(DateUtils.getNowDate());
        return alarmRuleMapper.insertAlarmRule(alarmRule);
    }

    /**
     * 修改告警规则
     * 
     * @param alarmRule 告警规则
     * @return 结果
     */
    @Override
    public int updateAlarmRule(AlarmRule alarmRule)
    {
        alarmRule.setUpdateTime(DateUtils.getNowDate());
        return alarmRuleMapper.updateAlarmRule(alarmRule);
    }

    /**
     * 批量删除告警规则
     * 
     * @param ids 需要删除的告警规则主键
     * @return 结果
     */
    @Override
    public int deleteAlarmRuleByIds(Long[] ids)
    {
        return alarmRuleMapper.deleteAlarmRuleByIds(ids);
    }

    /**
     * 删除告警规则信息
     * 
     * @param id 告警规则主键
     * @return 结果
     */
    @Override
    public int deleteAlarmRuleById(Long id)
    {
        return alarmRuleMapper.deleteAlarmRuleById(id);
    }

    /**
     * 查询告警规则
     *
     * @param deviceId 告警设备主键
     * @param alarmType 告警类型
     * @return 告警规则
     */
    @Override
    public List<AlarmRule> selectAlarmRuleByDevice(Long deviceId, String alarmType){
        return alarmRuleMapper.selectAlarmRuleByDevice(deviceId, alarmType);
    }
}
